package com.ysqcould.web.controller.Community;


import com.ysqcould.Community.domain.VolUser;
import com.ysqcould.Community.domain.vo.VoUserVo;
import com.ysqcould.Community.service.IVolUserService;
import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 志愿者义工信息Controller
 * 
 * @author ruoyi
 * @date 2022-06-30
 */
@RestController
@RequestMapping("/Community/user")
public class VolUserController extends BaseController
{
    @Autowired
    private IVolUserService volUserService;

    /**
     * 查询志愿者义工信息列表
     */
    @PreAuthorize("@ss.hasPermi('Community:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(VolUser volUser)
    {
        startPage();
        List<VoUserVo> list = volUserService.selectVolUserList(volUser);
        return getDataTable(list);
    }

    /**
     * 导出志愿者义工信息列表
     */
    @PreAuthorize("@ss.hasPermi('Community:user:export')")
    @Log(title = "志愿者义工信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VolUser volUser)
    {
        List<VoUserVo> list = volUserService.selectVolUserList(volUser);
        ExcelUtil<VoUserVo> util = new ExcelUtil<VoUserVo>(VoUserVo.class);
        util.exportExcel(response, list, "志愿者义工信息数据");
    }

    /**
     * 获取志愿者义工信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('Community:user:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(volUserService.selectVolUserById(id));
    }

    /**
     * 新增志愿者义工信息
     */
    @PreAuthorize("@ss.hasPermi('Community:user:add')")
    @Log(title = "志愿者义工信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VolUser volUser)
    {
        volUser.setAsId(getUserId());
        return toAjax(volUserService.insertVolUser(volUser));
    }

    /**
     * 修改志愿者义工信息
     */
    @PreAuthorize("@ss.hasPermi('Community:user:edit')")
    @Log(title = "志愿者义工信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VolUser volUser)
    {
        return toAjax(volUserService.updateVolUser(volUser));
    }

    /**
     * 删除志愿者义工信息
     */
    @PreAuthorize("@ss.hasPermi('Community:user:remove')")
    @Log(title = "志愿者义工信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(volUserService.deleteVolUserByIds(ids));
    }
}
